package cn.edu.hqu.cst.android.cxy.test2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class UC3 extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);
        FrameLayout a = findViewById(R.id.page);
        ImageView a1 = findViewById(R.id.page1);
        ImageView a2 = findViewById(R.id.page2);
        ImageView a3 = findViewById(R.id.page3);
        ImageView a4 = findViewById(R.id.page4);
        ImageView a5 = findViewById(R.id.page5);
        Chronometer total_time = findViewById(R.id.chronometer);
        total_time.setFormat("00:%S");
        total_time.setBase(SystemClock.elapsedRealtime());
        total_time.start();
        total_time.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
            @Override
            public void onChronometerTick(Chronometer total_time) {
                int Hours = Integer.parseInt(total_time.getText().toString().split(":")[0]);
                int Mins = Integer.parseInt(total_time.getText().toString().split(":")[1]);
                int Ss = Integer.parseInt(total_time.getText().toString().split(":")[2]);
                int total = Hours * 3600 + Mins *60 + Ss;
                if (total % 5 == 0) {
                    a.setForeground(a5.getBackground());
                }
                if (total % 5 == 1) {
                    a.setForeground(a1.getBackground());
                }
                if (total % 5 == 2) {
                    a.setForeground(a2.getBackground());
                }
                if (total % 5 == 3) {
                    a.setForeground(a3.getBackground());
                }
                if (total % 5 == 4) {
                    a.setForeground(a4.getBackground());
                }
            }
        });
        Button button31 = findViewById(R.id.button31);
        button31.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i3 = new Intent(UC3.this, MainActivity.class);
                startActivity(i3);
            }
        });
    }
}